import ToastComponent from '../components/Toast.vue';
// import { createApp, createVNode, render } from 'vue';

export function Toast(message, duration = 2000) {
  // 创建虚拟节点
  // let vm = createVNode(ToastComponent, { message });
  const vm = createApp(ToastComponent, { message })
  // 创建div容器
  const container = document.createElement('div')
  document.body.appendChild(container)
  // 渲染虚拟节点
  // render(vm, container);
  vm.mount(container)

  setTimeout(() => {
    // 卸载
    // vm = null;
    vm.unmount(container)
    document.body.removeChild(container);
  }, duration)
}

export default {
  install: (app, options) => {
    // 在这里编写插件代码
    // app.$toast = Toast;
    // app.config.globalProperties.$toast = Toast;
    app.provide('toast', Toast);
  }
}

